/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "ssd2828.h"
#include "dsi_reciver_chip.h"
//#include "R69434.h"
//#include "ST7796S__PH035NA_01B.h"
//#include "ST7703__BV055HDE_N47_3Q00.h"

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_NVIC_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

int _write(int file, char *ptr, int len)
{
  
  HAL_UART_Transmit(&huart1, (uint8_t *)ptr, len, 0xff);
    
  return len;
}


void init_ILI9881(void){
  MIPI_WR(0x39, 0xFF, 0x98, 0x81, 0x03);
  MIPI_WR(0x39, 0x01, 0x00);           
  MIPI_WR(0x39, 0x02, 0x00);           
  MIPI_WR(0x39, 0x03, 0x73);           
  MIPI_WR(0x39, 0x04, 0x00);           
  MIPI_WR(0x39, 0x05, 0x00);           
  MIPI_WR(0x39, 0x06, 0x08);           
  MIPI_WR(0x39, 0x07, 0x00);           
  MIPI_WR(0x39, 0x08, 0x00);           
  MIPI_WR(0x39, 0x09, 0x00);           
  MIPI_WR(0x39, 0x0A, 0x01);           
  MIPI_WR(0x39, 0x0B, 0x01);           
  MIPI_WR(0x39, 0x0C, 0x00);        // STV  DUTY     
  MIPI_WR(0x39, 0x0D, 0x01);       //  STV  DUTY         
  MIPI_WR(0x39, 0x0E, 0x01);           
  MIPI_WR(0x39, 0x0F, 0x00);           
  MIPI_WR(0x39, 0x10, 0x00);           
  MIPI_WR(0x39, 0x11, 0x00);           
  MIPI_WR(0x39, 0x12, 0x00);           
  MIPI_WR(0x39, 0x13, 0x1F);        // CLK DUTY        
  MIPI_WR(0x39, 0x14, 0x1F);       //  CLK DUTY
  MIPI_WR(0x39, 0x15, 0x00);           
  MIPI_WR(0x39, 0x16, 0x00);           
  MIPI_WR(0x39, 0x17, 0x00);           
  MIPI_WR(0x39, 0x18, 0x00);           
  MIPI_WR(0x39, 0x19, 0x00);           
  MIPI_WR(0x39, 0x1A, 0x00);           
  MIPI_WR(0x39, 0x1B, 0x00);           
  MIPI_WR(0x39, 0x1C, 0x00);           
  MIPI_WR(0x39, 0x1D, 0x00);           
  MIPI_WR(0x39, 0x1E, 0x40);           
  MIPI_WR(0x39, 0x1F, 0xC0);           
  MIPI_WR(0x39, 0x20, 0x06);           
  MIPI_WR(0x39, 0x21, 0x01);           
  MIPI_WR(0x39, 0x22, 0x06);           
  MIPI_WR(0x39, 0x23, 0x01);           
  MIPI_WR(0x39, 0x24, 0x88);           
  MIPI_WR(0x39, 0x25, 0x88);           
  MIPI_WR(0x39, 0x26, 0x00);           
  MIPI_WR(0x39, 0x27, 0x00);           
  MIPI_WR(0x39, 0x28, 0x3B);           
  MIPI_WR(0x39, 0x29, 0x03);           
  MIPI_WR(0x39, 0x2A, 0x00);           
  MIPI_WR(0x39, 0x2B, 0x00);           
  MIPI_WR(0x39, 0x2C, 0x00);           
  MIPI_WR(0x39, 0x2D, 0x00);           
  MIPI_WR(0x39, 0x2E, 0x00);							//================2Eh           
  MIPI_WR(0x39, 0x2F, 0x00);           
  MIPI_WR(0x39, 0x30, 0x00);           
  MIPI_WR(0x39, 0x31, 0x00);           
  MIPI_WR(0x39, 0x32, 0x00);           
  MIPI_WR(0x39, 0x33, 0x00);           
  MIPI_WR(0x39, 0x34, 0x00);  // GPWR1/2 non overlap time 2.62us           
  MIPI_WR(0x39, 0x35, 0x00);           
  MIPI_WR(0x39, 0x36, 0x00);           
  MIPI_WR(0x39, 0x37, 0x00);           
  MIPI_WR(0x39, 0x38, 0x00);           
  MIPI_WR(0x39, 0x39, 0x00);           
  MIPI_WR(0x39, 0x3A, 0x00);           
  MIPI_WR(0x39, 0x3B, 0x00);           
  MIPI_WR(0x39, 0x3C, 0x00);           
  MIPI_WR(0x39, 0x3D, 0x00);           
  MIPI_WR(0x39, 0x3E, 0x00);           
  MIPI_WR(0x39, 0x3F, 0x00);           
  MIPI_WR(0x39, 0x40, 0x00);           
  MIPI_WR(0x39, 0x41, 0x00);           
  MIPI_WR(0x39, 0x42, 0x00);           
  MIPI_WR(0x39, 0x43, 0x00);           
  MIPI_WR(0x39, 0x44, 0x00);       
  MIPI_WR(0x39, 0x50, 0x01);           
  MIPI_WR(0x39, 0x51, 0x23);           
  MIPI_WR(0x39, 0x52, 0x45);           
  MIPI_WR(0x39, 0x53, 0x67);           
  MIPI_WR(0x39, 0x54, 0x89);           
  MIPI_WR(0x39, 0x55, 0xAB);           
  MIPI_WR(0x39, 0x56, 0x01);           
  MIPI_WR(0x39, 0x57, 0x23);           
  MIPI_WR(0x39, 0x58, 0x45);           
  MIPI_WR(0x39, 0x59, 0x67);           
  MIPI_WR(0x39, 0x5A, 0x89);           
  MIPI_WR(0x39, 0x5B, 0xAB);           
  MIPI_WR(0x39, 0x5C, 0xCD);           
  MIPI_WR(0x39, 0x5D, 0xEF);     
  MIPI_WR(0x39, 0x5E, 0x00);           
  MIPI_WR(0x39, 0x5F, 0x01);           
  MIPI_WR(0x39, 0x60, 0x01);           
  MIPI_WR(0x39, 0x61, 0x06);           
  MIPI_WR(0x39, 0x62, 0x06);           
  MIPI_WR(0x39, 0x63, 0x07);           
  MIPI_WR(0x39, 0x64, 0x07);           
  MIPI_WR(0x39, 0x65, 0x00);           
  MIPI_WR(0x39, 0x66, 0x00);           
  MIPI_WR(0x39, 0x67, 0x02);           
  MIPI_WR(0x39, 0x68, 0x02);           
  MIPI_WR(0x39, 0x69, 0x05);           
  MIPI_WR(0x39, 0x6A, 0x05);           
  MIPI_WR(0x39, 0x6B, 0x02);           
  MIPI_WR(0x39, 0x6C, 0x0D);           
  MIPI_WR(0x39, 0x6D, 0x0D);           
  MIPI_WR(0x39, 0x6E, 0x0C);           
  MIPI_WR(0x39, 0x6F, 0x0C);           
  MIPI_WR(0x39, 0x70, 0x0F);           
  MIPI_WR(0x39, 0x71, 0x0F);           
  MIPI_WR(0x39, 0x72, 0x0E);           
  MIPI_WR(0x39, 0x73, 0x0E);           
  MIPI_WR(0x39, 0x74, 0x02);           
  MIPI_WR(0x39, 0x75, 0x01);           
  MIPI_WR(0x39, 0x76, 0x01);           
  MIPI_WR(0x39, 0x77, 0x06);           
  MIPI_WR(0x39, 0x78, 0x06);           
  MIPI_WR(0x39, 0x79, 0x07);           
  MIPI_WR(0x39, 0x7A, 0x07);           
  MIPI_WR(0x39, 0x7B, 0x00);           
  MIPI_WR(0x39, 0x7C, 0x00);           
  MIPI_WR(0x39, 0x7D, 0x02);           
  MIPI_WR(0x39, 0x7E, 0x02);           
  MIPI_WR(0x39, 0x7F, 0x05);           
  MIPI_WR(0x39, 0x80, 0x05);           
  MIPI_WR(0x39, 0x81, 0x02);           
  MIPI_WR(0x39, 0x82, 0x0D);           
  MIPI_WR(0x39, 0x83, 0x0D);           
  MIPI_WR(0x39, 0x84, 0x0C);           
  MIPI_WR(0x39, 0x85, 0x0C);           
  MIPI_WR(0x39, 0x86, 0x0F);           
  MIPI_WR(0x39, 0x87, 0x0F);           
  MIPI_WR(0x39, 0x88, 0x0E);           
  MIPI_WR(0x39, 0x89, 0x0E);           
  MIPI_WR(0x39, 0x8A, 0x02);       
  MIPI_WR(0x39, 0xFF, 0x98, 0x81, 0x04);          
  MIPI_WR(0x39, 0x6C, 0x15);        //Set VCORE voltage =1.5V           
  MIPI_WR(0x39, 0x6E, 0x2A);        //di_pwr_reg=0 for power mode 2A //VGH clamp 18V           
  MIPI_WR(0x39, 0x6F, 0x33);    //45 //pumping ratio VGH=5x VGL=-3x                     
  MIPI_WR(0x39, 0x8D, 0x1B);        //VGL clamp -10V           
  MIPI_WR(0x39, 0x87, 0xBA);        //ESD  
  MIPI_WR(0x39, 0x3A, 0x24);        //POWER SAVING                     
  MIPI_WR(0x39, 0x26, 0x76);           
  MIPI_WR(0x39, 0xB2, 0xD1);           
  MIPI_WR(0x39, 0xFF, 0x98, 0x81, 0x01);           
  MIPI_WR(0x39, 0x22, 0x0A);        //BGR, 0x SS           
  MIPI_WR(0x39, 0x31, 0x00);        //Zigzag type3 inversion           
  MIPI_WR(0x39, 0x43, 0x66);                 
  MIPI_WR(0x39, 0x53, 0x42);                   
  MIPI_WR(0x39, 0x50, 0x87);                    
  MIPI_WR(0x39, 0x51, 0x82);                     
  MIPI_WR(0x39, 0x60, 0x15);  
  MIPI_WR(0x39, 0x61, 0x01); 
  MIPI_WR(0x39, 0x62, 0x0C); 
  MIPI_WR(0x39, 0x63, 0x00);          
  MIPI_WR(0x39, 0xA0, 0x00);    
  MIPI_WR(0x39, 0xA1, 0x13);        //VP251         
  MIPI_WR(0x39, 0xA2, 0x23);        //VP247 
  MIPI_WR(0x39, 0xA3, 0x14);        //VP243         
  MIPI_WR(0x39, 0xA4, 0x16);        //VP239         
  MIPI_WR(0x39, 0xA5, 0x29);        //VP231         
  MIPI_WR(0x39, 0xA6, 0x1E);        //VP219         
  MIPI_WR(0x39, 0xA7, 0x1D);        //VP203         
  MIPI_WR(0x39, 0xA8, 0x86);        //VP175         
  MIPI_WR(0x39, 0xA9, 0x1E);        //VP144         
  MIPI_WR(0x39, 0xAA, 0x29);        //VP111         
  MIPI_WR(0x39, 0xAB, 0x74);        //VP80          
  MIPI_WR(0x39, 0xAC, 0x19);        //VP52          
  MIPI_WR(0x39, 0xAD, 0x17);        //VP36          
  MIPI_WR(0x39, 0xAE, 0x4B);        //VP24          
  MIPI_WR(0x39, 0xAF, 0x20);        //VP16          
  MIPI_WR(0x39, 0xB0, 0x26);        //VP12          
  MIPI_WR(0x39, 0xB1, 0x4C);        //VP8           
  MIPI_WR(0x39, 0xB2, 0x5D);        //VP4           
  MIPI_WR(0x39, 0xB3, 0x3F);        //VP0          
  MIPI_WR(0x39, 0xC0, 0x00);        //VN255 GAMMA N           
  MIPI_WR(0x39, 0xC1, 0x13);        //VN251         
  MIPI_WR(0x39, 0xC2, 0x23);        //VN247         
  MIPI_WR(0x39, 0xC3, 0x14);        //VN243         
  MIPI_WR(0x39, 0xC4, 0x16);        //VN239         
  MIPI_WR(0x39, 0xC5, 0x29);        //VN231         
  MIPI_WR(0x39, 0xC6, 0x1E);        //VN219         
  MIPI_WR(0x39, 0xC7, 0x1D);        //VN203         
  MIPI_WR(0x39, 0xC8, 0x86);        //VN175         
  MIPI_WR(0x39, 0xC9, 0x1E);        //VN144         
  MIPI_WR(0x39, 0xCA, 0x29);        //VN111         
  MIPI_WR(0x39, 0xCB, 0x74);        //VN80          
  MIPI_WR(0x39, 0xCC, 0x19);        //VN52          
  MIPI_WR(0x39, 0xCD, 0x17);        //VN36          
  MIPI_WR(0x39, 0xCE, 0x4B);        //VN24          
  MIPI_WR(0x39, 0xCF, 0x20);        //VN16          
  MIPI_WR(0x39, 0xD0, 0x26);        //VN12          
  MIPI_WR(0x39, 0xD1, 0x4C);        //VN8           
  MIPI_WR(0x39, 0xD2, 0x5D);        //VN4           
  MIPI_WR(0x39, 0xD3, 0x3F);        //VN0
  MIPI_WR(0x39, 0xFF, 0x98, 0x81, 0x00);
  MIPI_WR(0x39, 0x35, 0x00);  // TE On
}

void init_wlac_01(void) {
	MIPI_WR(0x39,0xFF,0x98,0x81,0x03);
	MIPI_WR(0x39,0x01,0x00);
	MIPI_WR(0x39,0x02,0x00);
	MIPI_WR(0x39,0x03,0x73);
	MIPI_WR(0x39,0x04,0x06);
	MIPI_WR(0x39,0x05,0x00);
	MIPI_WR(0x39,0x06,0x08);
	MIPI_WR(0x39,0x07,0x06);
	MIPI_WR(0x39,0x08,0x00);
	MIPI_WR(0x39,0x09,0x00);
	MIPI_WR(0x39,0x0a,0x00);
	MIPI_WR(0x39,0x0b,0x00);
	MIPI_WR(0x39,0x0c,0x00);
	MIPI_WR(0x39,0x0d,0x00);
	MIPI_WR(0x39,0x0e,0x00);
	MIPI_WR(0x39,0x0f,0x3F);
	MIPI_WR(0x39,0x10,0x3F);
	MIPI_WR(0x39,0x11,0x00);
	MIPI_WR(0x39,0x12,0x00);
	MIPI_WR(0x39,0x13,0x00);
	MIPI_WR(0x39,0x14,0x00);
	MIPI_WR(0x39,0x15,0x00);
	MIPI_WR(0x39,0x16,0x00);
	MIPI_WR(0x39,0x17,0x00);
	MIPI_WR(0x39,0x18,0x00);
	MIPI_WR(0x39,0x19,0x00);
	MIPI_WR(0x39,0x1a,0x00);
	MIPI_WR(0x39,0x1b,0x00);
	MIPI_WR(0x39,0x1c,0x00);
	MIPI_WR(0x39,0x1d,0x00);
	MIPI_WR(0x39,0x1e,0x40);
	MIPI_WR(0x39,0x1f,0x80);
	MIPI_WR(0x39,0x20,0x06);
	MIPI_WR(0x39,0x21,0x01);
	MIPI_WR(0x39,0x22,0x00);
	MIPI_WR(0x39,0x23,0x00);
	MIPI_WR(0x39,0x24,0x00);
	MIPI_WR(0x39,0x25,0x00);
	MIPI_WR(0x39,0x26,0x00);
	MIPI_WR(0x39,0x27,0x00);
	MIPI_WR(0x39,0x28,0x33);
	MIPI_WR(0x39,0x29,0x33);
	MIPI_WR(0x39,0x2a,0x00);
	MIPI_WR(0x39,0x2b,0x00);
	MIPI_WR(0x39,0x2c,0x00);
	MIPI_WR(0x39,0x2d,0x00);
	MIPI_WR(0x39,0x2e,0x00);
	MIPI_WR(0x39,0x2f,0x00);
	MIPI_WR(0x39,0x30,0x00);
	MIPI_WR(0x39,0x31,0x00);
	MIPI_WR(0x39,0x32,0x00);
	MIPI_WR(0x39,0x33,0x00);
	MIPI_WR(0x39,0x34,0x00);
	MIPI_WR(0x39,0x35,0x00);
	MIPI_WR(0x39,0x36,0x00);
	MIPI_WR(0x39,0x37,0x00);
	MIPI_WR(0x39,0x38,0x00);
	MIPI_WR(0x39,0x39,0x00);
	MIPI_WR(0x39,0x3a,0x00);
	MIPI_WR(0x39,0x3b,0x00);
	MIPI_WR(0x39,0x3c,0x00);
	MIPI_WR(0x39,0x3d,0x00);
	MIPI_WR(0x39,0x3e,0x00);
	MIPI_WR(0x39,0x3f,0x00);
	MIPI_WR(0x39,0x40,0x00);
	MIPI_WR(0x39,0x41,0x00);
	MIPI_WR(0x39,0x42,0x00);
	MIPI_WR(0x39,0x43,0x00);
	MIPI_WR(0x39,0x44,0x00);
	MIPI_WR(0x39,0x50,0x01);
	MIPI_WR(0x39,0x51,0x23);
	MIPI_WR(0x39,0x52,0x44);
	MIPI_WR(0x39,0x53,0x67);
	MIPI_WR(0x39,0x54,0x89);
	MIPI_WR(0x39,0x55,0xab);
	MIPI_WR(0x39,0x56,0x01);
	MIPI_WR(0x39,0x57,0x23);
	MIPI_WR(0x39,0x58,0x45);
	MIPI_WR(0x39,0x59,0x67);
	MIPI_WR(0x39,0x5a,0x89);
	MIPI_WR(0x39,0x5b,0xab);
	MIPI_WR(0x39,0x5c,0xcd);
	MIPI_WR(0x39,0x5d,0xef);
	MIPI_WR(0x39,0x5e,0x00);
	MIPI_WR(0x39,0x5f,0x0C);
	MIPI_WR(0x39,0x60,0x0C);
	MIPI_WR(0x39,0x61,0x0F);
	MIPI_WR(0x39,0x62,0x0F);
	MIPI_WR(0x39,0x63,0x0E);
	MIPI_WR(0x39,0x64,0x0E);
	MIPI_WR(0x39,0x65,0x06);
	MIPI_WR(0x39,0x66,0x07);
	MIPI_WR(0x39,0x67,0x0D);
	MIPI_WR(0x39,0x68,0x02);
	MIPI_WR(0x39,0x69,0x02);
	MIPI_WR(0x39,0x6a,0x02);
	MIPI_WR(0x39,0x6b,0x02);
	MIPI_WR(0x39,0x6c,0x02);
	MIPI_WR(0x39,0x6d,0x02);
	MIPI_WR(0x39,0x6e,0x0D);
	MIPI_WR(0x39,0x6f,0x02);
	MIPI_WR(0x39,0x70,0x02);
	MIPI_WR(0x39,0x71,0x05);
	MIPI_WR(0x39,0x72,0x01);
	MIPI_WR(0x39,0x73,0x08);
	MIPI_WR(0x39,0x74,0x00);
	MIPI_WR(0x39,0x75,0x0C);
	MIPI_WR(0x39,0x76,0x0C);
	MIPI_WR(0x39,0x77,0x0F);
	MIPI_WR(0x39,0x78,0x0F);
	MIPI_WR(0x39,0x79,0x0E);
	MIPI_WR(0x39,0x7a,0x0E);
	MIPI_WR(0x39,0x7b,0x06);
	MIPI_WR(0x39,0x7c,0x07);
	MIPI_WR(0x39,0x7d,0x0D);
	MIPI_WR(0x39,0x7e,0x02);
	MIPI_WR(0x39,0x7f,0x02);
	MIPI_WR(0x39,0x80,0x02);
	MIPI_WR(0x39,0x81,0x02);
	MIPI_WR(0x39,0x82,0x02);
	MIPI_WR(0x39,0x83,0x02);
	MIPI_WR(0x39,0x84,0x0D);
	MIPI_WR(0x39,0x85,0x02);
	MIPI_WR(0x39,0x86,0x02);
	MIPI_WR(0x39,0x87,0x05);
	MIPI_WR(0x39,0x88,0x01);
	MIPI_WR(0x39,0x89,0x08);
	MIPI_WR(0x39,0x8A,0x00);
	MIPI_WR(0x39,0xFF,0x98,0x81,0x04);
	MIPI_WR(0x39,0x6E,0x3B);
	MIPI_WR(0x39,0x6F,0x57);
	MIPI_WR(0x39,0x3A,0xA4);
	MIPI_WR(0x39,0x8D,0x1F);
	MIPI_WR(0x39,0x87,0xBA);
	MIPI_WR(0x39,0xB2,0xD1);
	MIPI_WR(0x39,0x88,0x0B);
	MIPI_WR(0x39,0x38,0x01);
	MIPI_WR(0x39,0x39,0x00);
	MIPI_WR(0x39,0xB5,0x07);
	MIPI_WR(0x39,0x31,0x75);
	MIPI_WR(0x39,0x3B,0x98);
	MIPI_WR(0x39,0xFF,0x98,0x81,0x01);
	MIPI_WR(0x39,0x22,0x0A);
	MIPI_WR(0x39,0x31,0x09);
	MIPI_WR(0x39,0x53,0x62);
	MIPI_WR(0x39,0x55,0x40);
	MIPI_WR(0x39,0x50,0x86);
	MIPI_WR(0x39,0x51,0x82);
	MIPI_WR(0x39,0x60,0x27);
	MIPI_WR(0x39,0x62,0x20);
	MIPI_WR(0x39,0xA0,0x00);
	MIPI_WR(0x39,0xA1,0x11);
	MIPI_WR(0x39,0xA2,0x1F);
	MIPI_WR(0x39,0xA3,0x13);
	MIPI_WR(0x39,0xA4,0x14);
	MIPI_WR(0x39,0xA5,0x28);
	MIPI_WR(0x39,0xA6,0x1D);
	MIPI_WR(0x39,0xA7,0x1F);
	MIPI_WR(0x39,0xA8,0x7A);
	MIPI_WR(0x39,0xA9,0x1C);
	MIPI_WR(0x39,0xAA,0x2A);
	MIPI_WR(0x39,0xAB,0x69);
	MIPI_WR(0x39,0xAC,0x1A);
	MIPI_WR(0x39,0xAD,0x18);
	MIPI_WR(0x39,0xAE,0x4D);
	MIPI_WR(0x39,0xAF,0x22);
	MIPI_WR(0x39,0xB0,0x29);
	MIPI_WR(0x39,0xB1,0x4C);
	MIPI_WR(0x39,0xB2,0x5B);
	MIPI_WR(0x39,0xB3,0x23);
	MIPI_WR(0x39,0xC0,0x00);
	MIPI_WR(0x39,0xC1,0x12);
	MIPI_WR(0x39,0xC2,0x1F);
	MIPI_WR(0x39,0xC3,0x12);
	MIPI_WR(0x39,0xC4,0x15);
	MIPI_WR(0x39,0xC5,0x29);
	MIPI_WR(0x39,0xC6,0x1D);
	MIPI_WR(0x39,0xC7,0x1E);
	MIPI_WR(0x39,0xC8,0x78);
	MIPI_WR(0x39,0xC9,0x1D);
	MIPI_WR(0x39,0xCA,0x29);
	MIPI_WR(0x39,0xCB,0x69);
	MIPI_WR(0x39,0xCC,0x19);
	MIPI_WR(0x39,0xCD,0x18);
	MIPI_WR(0x39,0xCE,0x4C);
	MIPI_WR(0x39,0xCF,0x21);
	MIPI_WR(0x39,0xD0,0x29);
	MIPI_WR(0x39,0xD1,0x4C);
	MIPI_WR(0x39,0xD2,0x5B);
	MIPI_WR(0x39,0xD3,0x23);
	MIPI_WR(0x39,0xFF,0x98,0x81,0x00);
	MIPI_WR(0x39,0x11,0x00);
	MIPI_WR(0x39,0x29,0x00);
	MIPI_WR(0x39,0x35,0x00);
}



/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();

  /* Initialize interrupts */
  MX_NVIC_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  printf("Program Start\r\n");

  // test spi
  /*spi_init();
  while(1)
  {
    spi_write(SPI_CMD, 0xa5);
    HAL_Delay(10);
    spi_write(SPI_DAT, 0x5a);
    HAL_Delay(10);
  }*/

  uint8_t buf[128];
  
  SSD2828_POWER_ON();
  
  SSD2828_CS_0();
	SSD2828_LP();
  SSD2828_Config(); //配置SS2828
  
  
  
  //init_ILI9881();
  init_wlac_01();

  //MIPI_WR(0x05, 0x11); // Sleep-Out
	//HAL_Delay(120);
	//MIPI_WR(0x05, 0x29); // Display On
	//HAL_Delay(20);

  SSD2828_DcsReadDT06(0X04, 4, buf);
  printf("SSD2828 reg04: %02x %02x %02x %02x \r\n", buf[0], buf[1], buf[2], buf[3]);

  

  SSD2828_Video();

  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
    
    HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
    printf("Loop...\r\n");
    HAL_Delay(3000);
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief NVIC Configuration.
  * @retval None
  */
static void MX_NVIC_Init(void)
{
  /* USART1_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(USART1_IRQn);
}

/**
  * @brief USART1 Initialization Function
  * @param None
  * @retval None
  */
static void MX_USART1_UART_Init(void)
{

  /* USER CODE BEGIN USART1_Init 0 */

  /* USER CODE END USART1_Init 0 */

  /* USER CODE BEGIN USART1_Init 1 */

  /* USER CODE END USART1_Init 1 */
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART1_Init 2 */

  /* USER CODE END USART1_Init 2 */
}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, LCD_RST_Pin | LCD_CS_Pin | LCD_SCK_Pin | LCD_MOSI_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, SHUT_Pin | U_CON_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : LED_Pin */
  GPIO_InitStruct.Pin = LED_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : LCD_RST_Pin LCD_CS_Pin LCD_SCK_Pin LCD_MOSI_Pin */
  GPIO_InitStruct.Pin = LCD_RST_Pin | LCD_CS_Pin | LCD_SCK_Pin | LCD_MOSI_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : LCD_MISO_Pin */
  GPIO_InitStruct.Pin = LCD_MISO_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(LCD_MISO_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : SHUT_Pin U_CON_Pin */
  GPIO_InitStruct.Pin = SHUT_Pin | U_CON_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */

  /* USER CODE END Error_Handler_Debug */
}

#ifdef USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
